#include "RoamingGangster.h"
#include "Mob.h"
#include "Field.h"

#include <stdlib.h>
#include <time.h>

bool RoamingGangster::action( QKeyEvent* ) {
    bool returnValue = false;
    #ifdef AIENABLED
    Mob* m = getMob();
    int speed = m->getMoveSpeed();
    for( int i = 0; i < speed; i++ ) {
            /*if( !powerSwitch ) {
                if( m->getTeam() == TEAMENUM ) {
                    findPath( m->getX(), m->getY(), 1, 98 );
                } else {
                    if( player == 0 ) findPath( m->getX(), m->getY(), 98, 1 );
                    else findPath( m->getX(), m->getY(),
                                   player->getX(), player->getY() );
                }
            } else {
                if( m->getTeam() == TEAMID ) {
                    if( player == 0 ) findPath( m->getX(), m->getY(), 1, 98 );
                    else findPath( m->getX(), m->getY(),
                                   player->getX(), player->getY() );
                } else {
                    findPath( m->getX(), m->getY(), 98, 1 );
                }
            }*/
        /*if( ( (m->getX() <= 4  && m->getY() >= 95) ||
            (m->getX() >= 95 && m->getY() <= 4) ) &&
            turns == 0 ) {
            if( powerSwitch ) powerSwitch = false;
            else powerSwitch = true;
            turns = 40;
        }
        if( turns > 0 ) turns--;*/
        if( turns <= 0 ){
              // srand(time(NULL));
            direction = randDirection();
            turns = rand() % 7;
        }else{
            if( rand() % 30 == 17 ) direction = randDirection();
        }
        --turns;
        if( !m->getField()->move( direction, 1, m ) ){
            turns = 0;
            m->getField()->move( randDirection(), 1, m );
        }
        Direction d = m->getField()->enemyInSight( m );
        if( d != NONE ) m->attack( d );
    }
    #endif
    return returnValue;
}
